package com.casstime.demo.controller;

import com.casstime.demo.dao.User;
import com.casstime.demo.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class DemoController {

    @Autowired
    private DemoService demoService;

    @RequestMapping(value = "/user", method = RequestMethod.GET)
    @ResponseBody
    public User getUser(){
        return demoService.findUser("小明");
    }

    @RequestMapping(value = "/userpage", method = RequestMethod.GET)
    public ModelAndView getUserPage(){
        ModelAndView mav = new ModelAndView();
        mav.setViewName("/user/user");
        User user = demoService.findUser("小明");
        mav.addObject("user", user);
        return mav;
    }


}
